package demo1;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 *
 * 使用Spring容器来管理项目中要使用的所有类
 * 将创建和初始化类等操作的控制权转交给Spring容器来管理被称为“控制反转
 */
public class Demo {
    public static void main(String[] args) throws Exception {
        User user = new User();
        user.sayHello();

        //反射
        Class cls =Class.forName("demo1.User");
        User user1 = (User) cls.newInstance();
        user1.sayHello();

        //Spring容器
        AnnotationConfigApplicationContext context
                =new AnnotationConfigApplicationContext("demo1");

        User user2=context.getBean(User.class);
        user2.sayHello();
    }
}
